package com.yzx.lifeassistants.fragment;

import java.util.ArrayList;
import java.util.List;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.yzx.lifeassistants.R;
import com.yzx.lifeassistants.adapter.CampusNewsGridAdapter;
import com.yzx.lifeassistants.bean.ClassifyItem;
import com.yzx.lifeassistants.listener.CampusNewsGridListener;
import com.yzx.lifeassistants.view.widget.CustomGridView;

/**
 * @Description: 校园资讯
 * @author: yzx
 * @time: 2015-9-23 下午4:18:10
 */
public class CampusNewsFragment extends Fragment {
	private TextView titleTV;// 标题
	private CustomGridView typeGV;// 分类

	private CampusNewsGridAdapter adapter;// 分类适配器
	private List<ClassifyItem> typeList;// 分类列表

	@Override
	@Nullable
	public View onCreateView(LayoutInflater inflater,
			@Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
		View view = inflater.inflate(R.layout.fragment_campus_news, container,
				false);
		return view;
	}

	@Override
	public void onActivityCreated(@Nullable Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);
		initView();
		initData();
	}

	/**
	 * 
	 * @Description: 初始化控件
	 */
	private void initView() {
		titleTV = (TextView) getView().findViewById(R.id.top_title_tv);
		typeGV = (CustomGridView) getView().findViewById(R.id.campus_news_gv);
	}

	/**
	 * 
	 * @Description: 初始化数据
	 */
	private void initData() {
		titleTV.setText("校园资讯");
		typeList = new ArrayList<ClassifyItem>();
		adapter = new CampusNewsGridAdapter(getActivity(), typeList);
		typeGV.setAdapter(adapter);
		typeGV.setOnItemClickListener(new CampusNewsGridListener(getActivity(),
				typeList));
		ClassifyItem officeItem = new ClassifyItem("0", R.drawable.icon_office,
				"教务处");
		ClassifyItem lectureItem = new ClassifyItem("1",
				R.drawable.icon_lecture, "讲座");
		ClassifyItem jobItem = new ClassifyItem("2", R.drawable.icon_job, "招聘");
		ClassifyItem groupProjectItem = new ClassifyItem("3",
				R.drawable.icon_running, "约跑");
		ClassifyItem foodItem = new ClassifyItem("4",
				R.drawable.icon_near_food, "美食");
		ClassifyItem activityItem = new ClassifyItem("5",
				R.drawable.icon_activity, "活动");
		ClassifyItem libraryItem = new ClassifyItem("6",
				R.drawable.icon_library, "图书馆");
		ClassifyItem partTimeItem = new ClassifyItem("7",
				R.drawable.icon_part_time, "兼职");
		ClassifyItem livingItem = new ClassifyItem("8", R.drawable.icon_living,
				"生活");
		typeList.add(officeItem);
		typeList.add(lectureItem);
		typeList.add(jobItem);
		typeList.add(groupProjectItem);
		typeList.add(foodItem);
		typeList.add(activityItem);
		typeList.add(libraryItem);
		typeList.add(partTimeItem);
		typeList.add(livingItem);
		adapter.notifyDataSetChanged();
	}

}
